package com.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dao.DepDao;
import com.pojo.Dep;
import com.service.IDepService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DepServiceImpl implements IDepService {

    @Autowired
    private DepDao depDao;


    @Override
    public List findAll() {

        return depDao.selectList(null);
    }

    @Override
    public IPage<Dep> search(int page, int limit, Integer depId, String depName) {
        //封装分页参数
        Page pageParam=new Page(page,limit);

        //封装查询条件
        QueryWrapper q=new QueryWrapper();
        if (depId!=null){
            q.eq("depId",depId);
        }

        if(depName!=null&& depName.length()>0){
            q.like("depName","%"+depName+"%");
        }

        //查询
        IPage result=depDao.selectPage(pageParam,q);


        return result;
    }
}
